package simple

// https://leetcode-cn.com/problems/isomorphic-strings/
// 字符映射
func IsIsomorphic(s string, t string) bool {
	// 注意左右映射并不要求对称，因此需要两个map
	matchLeftMap := make(map[uint8]uint8)
	matchRightMap := make(map[uint8]uint8)
	if len(s) != len(t) {
		return false
	}

	len := len(s)
	for index := 0; index < len; index++ {
		leftChar := s[index]
		rightChar := t[index]
		matchRightChar := matchLeftMap[leftChar]
		matchLeftChar := matchRightMap[rightChar]
		if matchLeftChar == 0 && matchRightChar == 0 {
			matchLeftMap[leftChar] = rightChar
			matchRightMap[rightChar] = leftChar
		} else if leftChar != matchLeftChar || rightChar != matchRightChar {
			return false
		}
	}
	return true
}
